<template>
  <u-dialog v-model="display_"
            :title="$t('about.title')"
            type="none">
    <div v-html="markdown(aboutFile)"/>
    <q-inner-loading :showing="loading">
      <q-spinner-grid/>
    </q-inner-loading>
  </u-dialog>
</template>

<script>
  import UDialog from "src/components/public/UDialog";
  import showdown from 'showdown';
  import {readPlayerOptions} from "src/lib/playerOptionUtil";

  showdown.setOption('openLinksInNewWindow', true);
  let converter = new showdown.Converter();

  export default {
    name: "Info",
    components: {UDialog},
    props: {
      display: Boolean
    },
    data: function () {
      return {
        display_: this.display,
        loading: false,
        aboutFile: ''
      };
    },
    watch: {
      display(n) {
        this.display_ = n;
      },
      display_(n) {
        this.$emit('onDisplayChange', n)
      }
    },
    model: {
      prop: 'display',
      event: 'onDisplayChange'
    },
    methods: {
      markdown(text) {
        return converter.makeHtml(text);
      }
    },
    async mounted() {
      this.loading = true;
      let lang = readPlayerOptions().language;
      let res;
      try {
        let {data} = await this.$axios(`statics/about/${lang}.md`);
        if(data) res = data;
      } catch (e) {
        let {data} = await this.$axios(`statics/about/en_us.md`);
        if(data) res = data;
      }
      this.aboutFile = res;
      this.loading = false;
    }
  }
</script>

<style scoped>

</style>
